<?php
class ExternalLinksController extends AppController {

	var $name = 'ExternalLinks';

        function beforeFilter(){
		parent::beforeFilter();
	  	$this->Auth->allowedActions = array('*');

	}

	function index() {
		$this->ExternalLink->recursive = 0;
		$this->set('externalLinks', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid external link', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('externalLink', $this->ExternalLink->read(null, $id));
	}

	function add() {
            $this->layout=null;
		if (!empty($this->data)) {
                    $this->data['ExternalLink']['modified']=date('Y-m-d H:i:s');
			$this->ExternalLink->create();
			if ($this->ExternalLink->save($this->data)) {
			$this->render('addsuccess');
			} else {
				//$this->Session->setFlash(__('The external link could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
            $this->layout=null;
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid external link', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
                     $this->data['ExternalLink']['modified']=date('Y-m-d H:i:s');
			if ($this->ExternalLink->save($this->data)) {
				$this->render('updatesuccess');
			} else {
				//$this->Session->setFlash(__('The external link could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->ExternalLink->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for external link', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->ExternalLink->delete($id)) {
			$this->Session->setFlash(__('External link deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('External link was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	function backstage_index() {
            $this->layout='admin';
		$this->ExternalLink->recursive = 0;
		$this->set('externalLinks', $this->paginate());
	}

	function backstage_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid external link', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('externalLink', $this->ExternalLink->read(null, $id));
	}

	function backstage_add() {
		if (!empty($this->data)) {
			$this->ExternalLink->create();
			if ($this->ExternalLink->save($this->data)) {
				$this->Session->setFlash(__('The external link has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The external link could not be saved. Please, try again.', true));
			}
		}
	}

	function backstage_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid external link', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->ExternalLink->save($this->data)) {
				$this->Session->setFlash(__('The external link has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The external link could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->ExternalLink->read(null, $id);
		}
	}

	function backstage_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for external link', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->ExternalLink->delete($id)) {
			$this->Session->setFlash(__('The link deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('The link was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>